#!/usr/bin/env python3 
# -*- coding: UTF-8 -*-

'''
入口模块
by lina
'''
import time
import datetime
import os
from xlwt import *
from src.util import constants
from src.util import config
from src.util import driver
from src.gui.story import demo_story

class Index:
	"""
	入口函数，定义要执行的store
	by lina
	"""
	def index(self):
		#初始化模块
		conf = config.Config()
		constants._init()
		now_time = datetime.datetime.now()

		#设置当次测试日志输出的文件夹与文件
		log_path = conf.get_config('system','log_path')
		log_folder = log_path + now_time.strftime('%Y-%m-%d')
		log_file = now_time.strftime('%H%M%S')

		constants.set_value('log_folder',log_folder)
		constants.set_value('log_file',log_file)

		#设置当次测试截图输出的文件夹
		screenshot_path = conf.get_config('system','screenshot_path')
		screenshot_folder = screenshot_path + now_time.strftime('%Y-%m-%d_%H%M%S')
		constants.set_value('screenshot_folder',screenshot_folder)

		#设置当次测试excel报告输出的文件
		excel_report_path = conf.get_config('system','excel_report_path')
		excel_report_folder = excel_report_path + now_time.strftime('%Y-%m-%d')
		excel_report_file = now_time.strftime('%H%M%S')
		constants.set_value('excel_report_folder',excel_report_folder)
		constants.set_value('excel_report_file',excel_report_file)

		#创建导出excel报告的文件夹
		if not os.path.exists(excel_report_folder):
			os.makedirs(excel_report_folder)

		#导出excel报告
		excel_file = Workbook(encoding = 'utf-8')
		excel_sheet = excel_file.add_sheet('测试报告')
		for i in range(0,4):
			excel_sheet.col(i).width = 256*40

		excel_sheet.write(0, 0, label = '测试故事')
		excel_sheet.write(0, 1, label = '测试行为')
		excel_sheet.write(0, 2, label = '描述')
		excel_sheet.write(0, 3, label = '测试时间')
		excel_file.save(excel_report_folder+'/'+excel_report_file+'.xls')


		#设置驱动
		driver_class = driver.Driver()
		my_driver = driver_class.get_driver()
		constants.set_value('my_driver',my_driver)

		#测试写入excel

		#运行测试用例
		mdemo = demo_story.DemoStory()
		mdemo.story_one()


if __name__ == "__main__":
	ind = Index()
	ind.index()


